Skip to content

feat(desktop): refresh Agents tab live on inbound relay sync#1256

Open
wpfleger96 wants to merge 2 commits into
mainfrom
duncan/persona-sync-live-refresh
Open

feat(desktop): refresh Agents tab live on inbound relay sync#1256
wpfleger96 wants to merge 2 commits into
mainfrom
duncan/persona-sync-live-refresh

Conversation

@wpfleger96

Copy link
Copy Markdown
Collaborator

Inbound persona/team/managed-agent relay events are reconciled to disk on the receiving device, but nothing signaled the live UI — so another device's edit or deletion only appeared after an app restart. This wires the live refresh: the Agents tab now updates without a restart.

Changes

  • Backend (commands/personas.rs): both inbound reconcile paths — reconcile_inbound_persona_event (upserts, all three kinds) and reconcile_inbound_tombstone (deletions) — emit a coarse agents-data-changed Tauri event after their disk write commits. These are the only inbound writers to the agents stores, so two emit sites cover the full inbound surface.
  • Frontend (useAgentsDataRefresh.ts, new): a root-mounted listener invalidates the four agents React Query keys (personasQueryKey, teamsQueryKey, managedAgentsQueryKey, relayAgentsQueryKey) on that event.

Design notes

  • The listener mounts identity-agnostic at the AppShell root, not inside the pubkey-keyed usePersonaSync hook. Folding it in would re-register the listener on every identity switch and leak one per switch; invalidation is global and has no reason to be pubkey-scoped.
  • The listener debounces with a 200 ms trailing coalesce. A one-shot backfill feeds up to 500 inbound events through reconcile one-by-one, each emitting agents-data-changed; coalescing collapses the burst into a single invalidate rather than depending on React Query's implicit in-flight dedup and paying redundant disk-read IPC.
  • The backend emit is unconditional and coarse — it cannot distinguish a backfill burst from a live burst, so the burst handling lives entirely on the consumer side.

This is part of the persona/team/agent relay-sync arc and is the user-visible follow-on to #939 (which landed the publish + inbound-reconcile-to-disk substrate). The live cross-device round-trip is exercised by an E2E test and manual two-device smoke in the next phase — this PR's unit/lib gates do not prove the render path on their own.

Inbound persona/team/managed-agent relay events reconciled to disk but
never signaled the UI, so a device only saw another device's edits after
an app restart. The two inbound reconcile paths now emit a coarse
`agents-data-changed` event after their disk write commits, and a new
root-mounted listener invalidates the four agents query keys.

The listener mounts identity-agnostic (it does not live inside the
pubkey-keyed persona-sync hook, which would leak a listener per identity
switch) and debounces with a trailing coalesce so a backfill burst of up
to 500 events yields a single invalidate rather than leaning on React
Query's implicit in-flight dedup.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
@wpfleger96 wpfleger96 marked this pull request as draft June 24, 2026 23:03
reconcile_inbound_persona_event drives the full inbound path (upsert +
tombstone) and the agents-data-changed emit. Tests verify the record
lands in list_personas, the deletion removes it, and the emit fires on
both paths — covering the Phase 1 wiring that unit tests cannot reach.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
@wpfleger96 wpfleger96 marked this pull request as ready for review June 25, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant